articles

Home / DeveloperSection / Articles / Difference between session and cookie in C#

Difference between session and cookie in C#

Difference between session and cookie in C#

Ravi Vishwakarma1707 03-Jul-2021

Session

 A session create a temporary file in a directory on server, this session store in registered session variable and value store in session variable. This data are available to all pages on website during user visit this site a session close or destroy when user is close the browser or leave this site. This session can hold the any type of information and share whole website. Server terminate the session after time period, session minimum time period 30 minutes. Session value is much secure this is encrypt in binary format and this session in decrypt on server. Each session is unique to each other users, any number of session can be used in website. The user is identify by session id which is unique number save inside the server.

Working session


  1.  Client first request to server send through methods
  2.  Session id is created on server and it save session id in database and it return the cookie with session id and this cookie is store on client machine
  3.  Again we request to server then server match the id with save session id

Cookies
 Cookies are text file, this is store on client system, and this cookies are used to tracking the purpose of user experience on site. Server send a set of cookies to browser and this cookies store on client machine for future use eg system name, port no, id number etc. when next time browser send request to server then server identify the user. A cookies a small text file that is store on client machine and this file is maximum size is 4KB. It also known as http cookies, web cookies. When a new user visit the site then server send a cookie to bowser. The cookie help to track the user search history and cart information. It only store string datatype this cookies is not secure because cookies value is store in paint text format. We can enable disable cookie for our need. Cookie is generated by user this cannot be see any other cookie are created and share between servers to client machine. When we visit YouTube channel for listening the song, next time when we visit YouTube, cookies read browsing history and see similar song.

Types of Cookies

  1. Persist
  2. Non-Persist

    Cookie has no expire time then say persist cookie and cookie has expire time then say the non persist cookie.


Difference between session and cookies

  1. The main difference between both of them is that sessions are saved on the server-side, whereas cookies are saved on the user's browser or client-side.
  2. A session stores the variable and their value on server but in cookies are store client machine
  3.  Session ends when user logout the website or close his browser but cookies is set for life time
  4.  Session can store unlimited data but cookies store limited data
  5.  In session maximum memory limit is 128 MB but in cookie 4kb memory limit



Updated 03-Jul-2021
Hi, my self Ravi Vishwakarma. I have completed my studies at SPICBB Varanasi. now I completed MCA with 76% form Veer Bahadur Singh Purvanchal University Jaunpur. SWE @ MindStick | Software Engineer | Web Developer | .Net Developer | Web Developer | Backend Engineer | .NET Core Developer

Leave Comment

Comments

Liked By